<!-- 招聘岗位 -->
<template>
	<scroll-view @scrolltolower="onLower" @refresherrefresh="onRefresh" refresher-enabled="true"
		:refresher-threshold="40" :refresher-triggered="triggered" scroll-y="true" :style="{height: pageHeight - 90 + 'px'}">
		<uni-card v-for="(item,index) in listData" :key="index" spacing="0" :is-shadow="false" :border="false">
			<navigator :url="'/pages/student/recruit/details?itemID=' + item.id" hover-class="none">
				<view class="item-dom">
					<view class="flex-row flex-row-space-between">
						<text class="title text-hiden">{{item.positionName}}</text>
						<text class="money">{{item.recruitingNumbers}}人</text>
					</view>
					<view class="flex-row">
						<text class="iconfont icon-gongsi" style="padding-right: 15rpx;  color: #01c2b7"></text>
						<text>{{item.companyName}}</text>
					</view>
					<view class="flex-row">
						<text class="iconfont icon-dizhi" style="padding-right: 15rpx;  color: #01c2b7"></text>
						<text class="text-hiden">{{item.workPlace}}</text>
					</view>
					<view class="flex-row">
						<text class="tag-dom"> {{item.education}}</text>
						<text class="tag-dom">{{item.workTime}}</text>
					</view>
				</view>
			</navigator>
		</uni-card>
	</scroll-view>

	<uinloadmore :status="status" />

</template>

<script lang="ts" setup>
	import uinloadmore from "@/components/uni/uni-load-more"
	import { Recruit } from "@/api/tables/Recruit"
	import { recruitPage } from "@/api/recruit"
	import { ref, onBeforeMount } from 'vue'
	
	let pageHeight = ref(90)
	let listData = ref<Array<Recruit>>([])
	let total = ref(0)
	let pagination = ref({ current: 1, size: 10,  releaseStatus: 'RELEASED' })
	const triggered = ref<boolean>(false)
	let status = ref('noMore')

	onBeforeMount(() => {
		// 获取当前窗口高度
		pageHeight.value = uni.getSystemInfoSync().windowHeight
		// 监听窗口大小的变化
		uni.onWindowResize((res) => {
			pageHeight.value = res.size.windowHeight
		})
		getListData()
	})
	
	// 上拉加载
	function onLower() {
		if (total.value <= listData.value.length) {
			status.value = 'noMore'
		} else {
			status.value = 'loading'
			pagination.value.current++
			getListData()
		}
	}
	// 下拉刷新
	function onRefresh() {
		pagination.value.current = 1
		triggered.value = true
		getListData()
	}

	function getListData() {
		recruitPage({
			...pagination.value
		}).then(res => {
			if (res.code == '200') {
				let list = res.data.records
				listData.value = triggered.value ? list : listData.value.concat(list)
				total.value = res.data.total
				status.value = res.data.total <= listData.value.length ? 'noMore' : 'more'
				triggered.value = false
			}
		})
	}
</script>

<style lang="scss" scoped>
	.item-dom {
		font-size: 28rpx;
		color: #999999;
		font-family: "微软雅黑";

		.title {
			font-size: 30rpx;
			line-height: 2;
			color: #131313;
			font-weight: 600;
		}

		.money {
			text-align: right;
			width: 120px;
			font-size: 28rpx;
			color: #2b9395;
			font-weight: 600;
		}

		.tag-dom {
			margin: 0 5px 5px 0;
			padding: 5rpx 15rpx;
			font-size: 20rpx;
			background: #f6f6f6;
			border-color: #f6f6f6;
			border-radius: 2px;
			color: #999;
		}
	}
</style>